package org.example.kafka.selfserial;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
import org.example.kafka.common.CommonConstant;
import org.example.kafka.common.KafkaConstants;
import org.example.vo.DemoUser;

public class SelfSerialProducer {
    private static KafkaProducer<String, DemoUser> producer = null;

    public static void main(String[] args) {
        /*消息生产者*/
        producer = new KafkaProducer<String, DemoUser>(KafkaConstants.producerConfig(
                StringSerializer.class,SelfSerializer.class
        ));
        try{
            /*待发送的消息实例*/
            ProducerRecord<String,DemoUser> record;
            try {
                record =  new ProducerRecord<String,DemoUser>(
                        CommonConstant.SELF_SERIAL_TOPIC,"user01",
                        new DemoUser(1,"安路"));
                producer.send(record);
                System.out.println("sent ....");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }finally {
            producer.close();
        }
    }
}
